using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace Com.queryzer2.Cache
{
    public class CacheManager<T>
    {
        public static void set(CacheKeys key,T data)
        {
            if(exist(key)) HttpContext.Current.Cache[Convert.ToString(key)] = data;
            else HttpContext.Current.Cache.Insert(Convert.ToString(key),data);
        }

        public static void del(CacheKeys key)
        {
            HttpContext.Current.Cache.Remove(Convert.ToString(key));
        }

        public static T get(CacheKeys key)
        {
            if(HttpContext.Current.Cache[Convert.ToString(key)] != null)
                return (T)HttpContext.Current.Cache[Convert.ToString(key)];
            else return default(T);
        }

        public static bool exist(CacheKeys key)
        {
            bool bRet = false;
            if(HttpContext.Current.Cache[Convert.ToString(key)] != null)
                bRet = true;
            return bRet;
        }
    }
}
